package cn.wolfcode.rbac.util;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2020/6/11 0011.
 */
@Getter
@Setter
public class PageResult {
    public static final PageResult DEFAULT_PAGE = new PageResult(1,5, Collections.emptyList(),0);
    //当前页
    private Integer currentPage; //2
    //每页显示的数据
    private Integer pageSize;  //5

    //分页以后集合的数据
    private List list;
    //数据库表中的总条数;
    private Integer count;   // 13
    // 总页数
    private Integer endPage;  //5
    //上一页
    private Integer prePage;
    //下一页
    private Integer nextPage;


    public PageResult(Integer currentPage, Integer pageSize, List list, Integer count) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.count = count;

        this.endPage =  count % pageSize == 0 ? count / pageSize : count / pageSize +1 ;
        this.nextPage=  this.currentPage + 1 <= this.endPage ? this.currentPage+1 : endPage;
        this.prePage =  this.currentPage -1 >= 1 ? this.currentPage - 1 : 1;
    }
}
